package com.jzo2o.foundations.controller.operation;


import com.jzo2o.api.foundations.dto.response.ServeItemResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.*;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeItemService;
import com.jzo2o.foundations.service.impl.ServeServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务
 * </p>
 *
 * @author itcast
 * @since 2023-07-03
 */
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Autowired
    private ServeServiceImpl serveService;

    @GetMapping("/page")
    @ApiOperation("服务项分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        return serveService.findPage(servePageQueryReqDTO);
    }


    @PostMapping("/batch")
    @ApiOperation("区域新增")
    public Result add(@RequestBody List<ServeUpsertReqDTO> dtoList  ) {
        serveService.add(dtoList);
        return Result.ok();
    }


    @PutMapping("/{id}")
    @ApiOperation("区域服务修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "区域服务修改之后的价格", required = true, dataTypeClass = BigDecimal.class),
    })
    public Result update(@PathVariable Long id, BigDecimal price) {
        Serve serve = new Serve();
        serve.setId(id);
        serve.setPrice(price);
        serveService.updateById(serve);
        return Result.ok();
    }



    @DeleteMapping("/{id}")
    @ApiOperation("区域服务删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class)
    })
    public void delete(@NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        serveService.deleteById(id);
    }

    //PUT  /foundations/operation/serve/onSale/{id}
    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class),
    })
    public void update(@NotNull(message = "id不能为空") @PathVariable("id") Long id){

        serveService.OnSate(id);
    }

    ///serve/offSale/1734127645987192833
    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class),
    })
    public void offSale(@NotNull(message = "id不能为空") @PathVariable("id") Long id){
        serveService.offSale(id);
    }


    /**
     * 设置区域服务热门状态
     * @param id
     */
    @PutMapping("/onHot/{id}")
    @ApiOperation("区域服务设置热门")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class),
    })
    public void onHot(@NotNull(message = "id不能为空") @PathVariable("id") Long id){
        serveService.OnHot(id);
    }



    /**
     * 取消区域服务热门状态
     * @param id
     */
    @PutMapping("/offHot/{id}")
    @ApiOperation("区域服务取消热门")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class),
    })
    public void offHot(@NotNull(message = "id不能为空") @PathVariable("id") Long id){
        serveService.offHot(id);
    }




}
